<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ page import="java.util.*"%>
<%@ page
	import="cn.myapps.core.validate.repository.action.ValidateRepositoryHelper"%>
<ww:bean name="cn.myapps.core.dynaform.form.action.FormHelper" id="fh">
	<ww:param name="moduleid" value="#parameters.moduleid" />
</ww:bean>

<ww:bean name="cn.myapps.core.role.action.RoleHelper" id="rh">
	<ww:param name="applicationid" value="#parameters.application" />
</ww:bean>

<ww:bean name="cn.myapps.core.role.ejb.RoleVO" id="vh"/>
<html><o:MultiLanguage>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="0">
<link href="../css/dialog.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href='<ww:url value="/resource/css/main.css" />' type="text/css">
<script src='<ww:url value="/dwr/util.js"/>'></script>
<script src='<ww:url value="/dwr/engine.js"/>'></script>
<script src='<ww:url value="/dwr/interface/Sequence.js"/>'></script>
<script src='<ww:url value="/script/prototype.js"/>'></script>
<script src='<ww:url value="/dwr/interface/FormHelper.js"/>'></script>
<script language=JavaScript src="../../dialog/sequence.js"></script>
<script language=JavaScript src="../../dialog/dialog.js"></script>
<script language=JavaScript src="../../dialog/script.js"></script>
<script src="../../dialog/common/fck_dialog_common.js" type="text/javascript"></script>
<link href="../../css/dialog.css" rel="stylesheet" type="text/css" />

<SCRIPT language=JavaScript>
var dialog	= window.parent ;
var oEditor = dialog.InnerDialogLoaded() ;
// Gets the document DOM
var oDOM = oEditor.FCK.EditorDocument ;
var oActiveEl = dialog.Selection.GetSelectedElement() ;

// 选项卡点击事件
function cardClick(cardID){
	var obj;
	for (var i=1;i<6;i++){
		obj=document.all("card"+i);
		obj.style.backgroundColor="#3A6EA5";
		obj.style.color="#FFFFFF";
	}
	obj=document.all("card"+cardID);
	obj.style.backgroundColor="#FFFFFF";
	obj.style.color="#3A6EA5";

	for (var i=1;i<6;i++){
		obj=document.all("content"+i);
		obj.style.display="none";
	}
	obj=document.all("content"+cardID);
	obj.style.display="";
	resize();
}

//初始值
function InitDocument(){
	var editMode;
	oEditor.FCKLanguageManager.TranslatePage(document) ;
		if (oActiveEl){
			temp.name.value = HTMLDencode(oActiveEl.name);
			temp.refreshOnChanged.checked = oActiveEl.refreshOnChanged == "true";
			temp.calculateOnRefresh.checked = oActiveEl.calculateOnRefresh == "true";
			temp.discript.value = HTMLDencode(oActiveEl.discript);
			temp.validateRule.value = HTMLDencode(oActiveEl.validateRule);
			if(oActiveEl.hiddenScript!=null){
				temp.hiddenScript.value = HTMLDencode(oActiveEl.hiddenScript);
			}

			if(oActiveEl.hiddenValue!=null){
				temp.hiddenValue.value = HTMLDencode(oActiveEl.hiddenValue);
			}

			if(oActiveEl.hiddenPrintScript!=null){
				temp.hiddenPrintScript.value = HTMLDencode(oActiveEl.hiddenPrintScript);
			}

			if(oActiveEl.printHiddenValue!=null){
				temp.printHiddenValue.value = HTMLDencode(oActiveEl.printHiddenValue);
			}
			temp.readonlyScript.value = HTMLDencode(oActiveEl.readonlyScript);
			temp.mobile.checked = oActiveEl.mobile == "true";
			editMode=HTMLDencode(oActiveEl.editMode);
			temp.textType.value = HTMLDencode(oActiveEl.textType);
			temp.limit.value = HTMLDencode(oActiveEl.limit);
			var libstr=HTMLDencode(oActiveEl.validateLibs);
			var lib=libstr.split(';');
			var validateLibs=document.getElementsByName('validateLibs');
		    for(var i=0; i< lib.length; i++){
		       for(var j=0; j< validateLibs.length; j++){
	 			if(validateLibs[j].value==lib[i]){
	 				validateLibs[j].checked=true;
	 					}
	 				}
	 			}
		}
		else
			oActiveEl = null ;
		dialog.SetOkButton( true ) ;
		dialog.SetAutoSize( true ) ;
		SelectField( 'name' ) ;
		//initForm();
		//modeChange(editMode);
		window.top.toThisHelpPage("application_module_form_info_advance_treedept");
		
}

function Ok()
{
	if(ev_check()){
	oEditor.FCKUndo.SaveUndoStep() ;
	var className="cn.myapps.core.dynaform.form.ejb.TreeDepartmentField";
	var id=getFieldId();
	var editMode=document.getElementsByName("editMode");
	var ed="";   
    for(var i=0;i<editMode.length;i++){
		  if(editMode[i].checked){
			   ed += editMode[i].value;
	      }
	    }	
	var validateLibs=document.getElementsByName('validateLibs');
	var libs='';
	for(var i=0; i< validateLibs.length; i++){
 		if(validateLibs[i].checked){
 			libs+=validateLibs[i].value+";";
 		}
 	}
 	libs=libs.substring(0,libs.length-1);
	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'SELECT', {
									classname: className,
									id: id,
									type:"text",
									name:HTMLEncode(temp.name.value),
									refreshOnChanged:HTMLEncode(temp.refreshOnChanged.checked+""),
									calculateOnRefresh:HTMLEncode(temp.calculateOnRefresh.checked+""),
									mobile: HTMLEncode(temp.mobile.checked+""),
									validateRule:HTMLEncode(temp.validateRule.value),
									hiddenScript:HTMLEncode(temp.hiddenScript.value),
									hiddenValue:HTMLEncode(temp.hiddenValue.value),//////
									hiddenPrintScript:HTMLEncode(temp.hiddenPrintScript.value),
									printHiddenValue:HTMLEncode(temp.printHiddenValue.value),
									readonlyScript:HTMLEncode(temp.readonlyScript.value),
									discript:HTMLEncode(temp.discript.value),
									
									fieldtype:"VALUE_TYPE_TEXT",
									textType:HTMLEncode(temp.textType.value),
									limit:HTMLEncode(temp.limit.value),
									istreedepartmentfield:true,
								   	validateLibs:HTMLEncode(libs),
									editMode:HTMLEncode(ed)
									} 
								   ) ;	
	return true ;
	}
}


//检查内容是否完成正确
function ev_check(){
   if(temp.name.value==''){
 	 alert("{*[page.name.notexist]*}");
	  return false;
   }else if(!changeLimit()){
	  return false;
   }
   return !checkStartChar(temp.name.value);
}

function checkStartChar(value){
	return IsDigit(value,"{*[page.name.startingit]*}");
}
function IsDigit(s,msg){
	var text = s.substring(0,1);
	var patrn=/^[0-9]{1}$/; 
	if(s=="action"){
	   	alert("action为关键字，不能作为字段名！");
	   	return true;
   	}else if (patrn.exec(text)){
		alert(msg);
		return true;
	}
	return false;
}  

//验证是否为数字类型
function changeLimit(){
	var s = document.getElementById("limit").value;
	var reg = /^[0-9]*[1-9][0-9]*$/;
	if(reg.test(s)){
		return true;
	}
	alert("{*[Limit]*}{*[Select]*}不是正整数");
	return false;
}

</script>

</HEAD>

<BODY bgcolor=menu onload="InitDocument()"">

<form name="temp">
		<table border="0" cellpadding="3" cellspacing="0" width="520px" >
			<tr>
				<td class="card" onclick="cardClick(1)" id="card1">{*[Basic]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(2)" id="card2">{*[Validate_Script]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(3)" id="card3">{*[Hidden_Script]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(4)" id="card4">{*[Hidden_Print_Script]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(5)" id="card5">{*[ReadOnly_Script]*}</td>
				<td width=2></td>
			</tr>
			<tr>
				<td valign="middle" colspan="13" bgcolor="#ffffff" align="center"
					width="100%">

				<table border=1 cellpadding=3 cellspacing=0 class="content"
					width="100%" id="content1" width="520px">
					<tr>
						<td class="commFont commLabel">{*[Name]*}:</td>
						<td><input type=text name="name" onchange="checkStartChar(this.value);"/></td>
						<td class="commFont commLabel">{*[TextType]*}:</td>
						<td><select name="textType">
							<option value="text" selected>{*[Common]*}</option>
							<option value="readonly">{*[Readonly]*}</option>
							<option value="hidden">{*[Hidden]*}</option>
						</select></td>
					</tr>
					<tr>
						<td class="commFont commLabel">
						{*[Limit]*}{*[Select]*}:
						</td>
						<td>
						<input type=text id="limit" name="limit" onchange="changeLimit()" width="4"/>
						</td>
						<td colspan="2" align="center">
						<input type=checkbox name="refreshOnChanged" value="true" />{*[Refresh]*}&nbsp;
						<input type=checkbox name="calculateOnRefresh" value="true" />{*[Recalculate]*}&nbsp;
						<input type=checkbox name="mobile" value="true" checked />{*[Mobile]*}&nbsp;
						</td>
					</tr>
					<tr>
						<td class="commLabel commFont">{*[Description]*}:</td>
						<td colspan="4"><textarea name="discript" style="width:100%;" rows="4"></textarea></td>
					</tr>
				</table>
					<table border=1 cellpadding=3 cellspacing=1 class="content"
						id="content2">
						<tr>
							<td width="25%">
							<table>
								<%
								String applicationid = request.getParameter("application");
							    ValidateRepositoryHelper vrhpler = new ValidateRepositoryHelper();
								Map map = vrhpler.get_validate(applicationid);
									for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
										Object id = (Object) iter.next();
										String name = (String) map.get(id);
								%><tr>
									<td><input type="checkbox" name="validateLibs"
										value="<%=(String)id %>" /><%=name%></td>
								</tr>
								<%
									}
								%>
							</table>
							</td>
							<td width="75%"><textarea name="validateRule" style="width:95%"
								rows="10"></textarea>
								<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('validateRule','{*[Script]*}{*[Editor]*}','{*[Validate_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
								</td>
						</tr>
					</table>

					<table border=1 cellpadding=3 cellspacing=0 class="content"
						id="content3" width="520px">
						<tr>
							<td><textarea name="hiddenScript" style="width:96%" rows="10"></textarea>
							<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('hiddenScript','{*[Script]*}{*[Editor]*}','{*[Hidden_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
							</td>
						</tr>
						<tr>
							<td>{*[hiddenValue]*}：<input id="hiddenValue" type="text" name="hiddenValue" /></td>
						</tr>
					</table>

					<table border=1 cellpadding=3 cellspacing=0 class="content"
						id="content4" width="520px">
						<tr>
							<td><textarea name="hiddenPrintScript" style="width:96%" rows="10"></textarea>
							<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('hiddenPrintScript','{*[Script]*}{*[Editor]*}','{*[Hidden_Print_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
							</td>
						</tr>
						<tr>
							<td>{*[Print]*}{*[hiddenValue]*}：<input  type="text" name="printHiddenValue" /></td>
						</tr>
					</table>

					<table border=1 cellpadding=3 cellspacing=0 class="content"
						id="content5" width="520px">
						<tr>
							<td><textarea name="readonlyScript" style="width:96%" rows="10"></textarea>
							<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('readonlyScript','{*[Script]*}{*[Editor]*}','{*[ReadOnly_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
							</td>
						</tr>
					</table>

					</td>
					</tr>
				</table>
		</form>

		<script language=javascript>
	cardClick(1);
</script>
</BODY>
</o:MultiLanguage>
</HTML>
